package booroo.swing;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.ImageIcon;
import javax.swing.JComboBox;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.ButtonGroup;
import javax.swing.SwingConstants;
import javax.swing.JCheckBox;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import javax.swing.JList;
import javax.swing.JScrollBar;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ScrollPaneConstants;
import javax.swing.DefaultComboBoxModel;

public class BComp extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JButton imgBtn;
	private JLabel imgLabel;
	private JCheckBox chkHyun;
	private JCheckBox chkHye;
	private JTextField txtBtn;
	private JPasswordField pwdBtn;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			BComp dialog = new BComp();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public BComp() {
		setBounds(100, 100, 1024, 768 );
		setLocationRelativeTo(null);
		setTitle("기본 컴퍼넌트");
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			imgBtn = new JButton("이미지버튼");
			imgBtn.setToolTipText("이미지버튼입니다!");
			imgBtn.setFont(new Font("굴림", Font.BOLD, 14));
			imgBtn.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					
				}
			});
			imgBtn.setIcon(new ImageIcon(BComp.class.getResource("/booroo/swing/images/icon/icon.png")));
		}
		{
			imgLabel = new JLabel("이미지레이블");
			imgLabel.setIcon(new ImageIcon("C:\\Users\\PC26\\Desktop\\여신2.png"));
			imgLabel.setFont(new Font("굴림", Font.BOLD, 14));
		}
		{
			chkHyun = new JCheckBox("지현");
		}
		{
			chkHye = new JCheckBox("혜교");
			chkHye.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					JCheckBox hg = (JCheckBox)e.getSource();
					if(hg.isSelected())
						txtBtn.setText("혜교");
					else
						txtBtn.setText("");
				}
			});
		}
		
		JCheckBox chkSuji = new JCheckBox("수지");
		chkSuji.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				JCheckBox c = (JCheckBox)e.getSource();
				if(c.isSelected())
					txtBtn.setText(c.getText());
					//JOptionPane.showMessageDialog(null, "수지가 선택되었어요!");
				else 
					txtBtn.setText("");
				
			}
		});
		
		JRadioButton radSuji = new JRadioButton("수지");
		radSuji.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				JRadioButton r = (JRadioButton)e.getSource();
				if(r.isSelected())
					txtBtn.setText(r.getText());
					//JOptionPane.showMessageDialog(null, "수지가 선택되었어요!");
				else
					txtBtn.setText("");
			}
		});
		contentPanel.add(radSuji);		
		JRadioButton radHye = new JRadioButton("혜교");
		contentPanel.add(radHye);
		JRadioButton radHyun = new JRadioButton("지현");
		contentPanel.add(radHyun);
		
		ButtonGroup rgroup = new ButtonGroup();
		rgroup.add(radSuji);
		rgroup.add(radHye);
		rgroup.add(radHyun);
		
		txtBtn = new JTextField();
		txtBtn.setColumns(10);
		
		pwdBtn = new JPasswordField();
		pwdBtn.setEchoChar('※');
		pwdBtn.setColumns(16);
		
		JButton txt1Btn = new JButton("입력문자보기");
		txt1Btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, txtBtn.getText());
				
			}
		});
		
		JButton pwd1Btn = new JButton("입력문자보기");
		pwd1Btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, pwdBtn.getPassword());
			}
		});
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setPreferredSize(new Dimension(150, 100));
		contentPanel.add(scrollPane);
		String[] data = {"수지","혜교","지현","혜자","민교","재현","중호","준석","대운"};
		final JList list = new JList(data);
		list.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(e.getClickCount() == 2)
					JOptionPane.showMessageDialog(null, (list.getSelectedIndex()+1) + " " + "/" + " " + list.getSelectedValue());
			}
		});
		scrollPane.setViewportView(list);
		
		JButton listBtn = new JButton("리스트선택보기");
		listBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, (list.getSelectedIndex()+1) + " " + "/" + " " + list.getSelectedValue());
			}
		});
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scrollPane_1.setPreferredSize(new Dimension(250, 200));
		contentPanel.add(scrollPane_1);
		String[] data1 = {"수지","혜교","지현","혜자","민교","재현","중호","준석","대운"};
		final JComboBox comboBox1 = new JComboBox(data1);
		comboBox1.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				JOptionPane.showMessageDialog(null, (comboBox1.getSelectedIndex()+1) + " " + "/" + comboBox1.getSelectedItem());
			}
		});
		
				
		
		JComboBox comboBox2 = new JComboBox();
		comboBox2.setModel(new DefaultComboBoxModel(new String[] {"수지","혜교","지현","혜자","민교","재현","중호","준석","대운"}));
		contentPanel.add(comboBox2);
		
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addContainerGap(230, Short.MAX_VALUE)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING, false)
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(imgBtn)
									.addPreferredGap(ComponentPlacement.UNRELATED))
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
										.addComponent(listBtn)
										.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
									.addGap(30)))
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING)
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(imgLabel)
									.addGap(42))
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
										.addGroup(gl_contentPanel.createSequentialGroup()
											.addComponent(pwdBtn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(pwd1Btn))
										.addGroup(gl_contentPanel.createSequentialGroup()
											.addComponent(txtBtn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addComponent(txt1Btn))
										.addGroup(gl_contentPanel.createSequentialGroup()
											.addComponent(radSuji)
											.addGap(18)
											.addComponent(radHye)
											.addGap(18)
											.addComponent(radHyun))
										.addGroup(gl_contentPanel.createSequentialGroup()
											.addComponent(chkSuji)
											.addGap(18)
											.addComponent(chkHye)
											.addGap(18)
											.addComponent(chkHyun)))
									.addGap(89))))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(184)
							.addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(comboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(comboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(268, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(5)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addComponent(imgLabel)
							.addGap(20)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(chkHye)
								.addComponent(chkSuji)
								.addComponent(chkHyun))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(radSuji)
								.addComponent(radHye)
								.addComponent(radHyun))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(txtBtn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(txt1Btn))
							.addGap(6)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(pwdBtn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(pwd1Btn)))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addComponent(imgBtn)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(listBtn)
							.addGap(30)
							.addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(148)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(comboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(comboBox2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addContainerGap(127, Short.MAX_VALUE))
		);
		
		
		
		
		contentPanel.setLayout(gl_contentPanel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
